﻿@imports Library

@Code
    ViewData("Title") = "Create"
    Dim defaultName As String = IIf(ViewBag.Owner="IA", "日常支出&杂物", "早餐")
    Dim defaultType As String = IIf(ViewBag.Owner="IA", "垫付", "支出")
    Dim defaultPayer As String = IIf(ViewBag.Owner="IA", "Nicole", ViewBag.Owner)
End Code

<div id="page">

    <div id="page_header" style="position:relative;">
        Create Record (@ViewBag.Owner)
    </div>

    <div id="page_body">
            
        <div class="IE_padding_hack">
	
        @Using Html.BeginForm("create", "Transaction", FormMethod.Post)
            
            @<input type="hidden" name="owner" value="@ViewBag.owner" />
                    
            @<table class="basic">
                <tr>
                    <th>@Html.LabelExtension("recorddate", "Date", True)</th>
                    <td>@Html.TextBox("recorddate", Now.ToString("yyyy-MM-dd"), New With {.id = "recorddate"})
                        <span class="red"> YYYY-MM-DD format.Required. </span></td>
                </tr><tr>
                    <th>@Html.LabelExtension("name", "Name", True)</th>
                    <td>@Html.RadioButtonList("name", New SelectList(SharedCalls.TransactionNameList(ViewBag.owner), defaultName), Nothing)</td>
                </tr><tr>
                    <th>@Html.LabelExtension("remark", "Remark")</th>
                    <td>@Html.TextBox("remark", "", New With {.class = "inputText", .id = "remark"})</td>
                </tr><tr>
                    <th>@Html.LabelExtension("amount", "Amount", True)</th>
                    <td>@Html.TextBox("amount", "", new with{.class="inputText", .id="amount"})</td>
                </tr><tr>
                    <th>@Html.LabelExtension("recordtype", "Type", True)</th>
                    <td>@Html.RadioButtonList("recordtype", New SelectList(SharedCalls.TransactionTypeList(ViewBag.owner), defaultType), Nothing)</td>
                </tr><tr>
                    <th>@Html.LabelExtension("payer", "Payer", True)</th>
                    <td>@Html.RadioButtonList("payer", New SelectList(SharedCalls.TransactionPayerList(ViewBag.owner), defaultPayer), Nothing)</td>
                </tr><tr>
                    <td colspan="2"><input type="submit" id="submit" value="Save" /> or 
                        @Html.ActionLink("Cancel", "index", "AccountPeriod", New With{.owner = ViewBag.Owner}, nothing)</td>
                </tr>
            </table>
		
        End Using

        </div>
                    
    </div>
        
</div>

@section Scripts

    <script type="text/javascript">

        $(function () {
            var index = 0;
            if ('@ViewBag.Owner' == "NICOLE") {
                index = 2;
            } else if ('@ViewBag.Owner' == "VINCENT") {
                index = 1;
            };
            $("#global_nav li a").eq(index).addClass("selected");

            $("#recorddate").datepicker({
                dateFormat: 'yy-mm-dd',
                defaultDate: $("#recorddate").text()
            });

            $(".radio-button-list").buttonset();

            if (index != 0) {
                $("#name").change(function () {
                    $("#remark").val($("#name :radio:checked").val());
                });
                $("#remark").val($("#name :radio:checked").val());
            }

            $("#submit").click(function () {
                var amount = $("#amount").val();
                if (IsNumeric(amount)) {
                    $("#amount").val(Math.round(amount));
                    return true;
                } else {
                    alert("amount is not a number!");
                    return false;
                };
            });
        });
    
    </script>

End Section